package edu.towson.cosc603.coffeemaker;

import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import junit.framework.TestCase;

/**
 *
 */
public class CoffeeMakerTest extends TestCase{
	private CoffeeMaker myCoffeeMaker;
	private Inventory inventory;
	private Recipe recipeCoffee;
	private Recipe recipeLatte;
	private Recipe recipeMocha;
	private Recipe recipeFrappuccino;
	private Recipe recipeCappuccino;
	
	/**
	 * Set up the Test Run by creating Objects.
	 * @throws Exception the exception
	 * 
	 */
	@Before
	public void setUp() {
		myCoffeeMaker = new CoffeeMaker();
		inventory = new Inventory();
				 
		recipeCoffee = new Recipe();
		recipeCoffee.setName("Coffee");
		recipeCoffee.setPrice(70);
		recipeCoffee.setAmtCoffee(6);
		recipeCoffee.setAmtMilk(1);
		recipeCoffee.setAmtSugar(1);
		recipeCoffee.setAmtChocolate(0);

		recipeLatte = new Recipe();
		recipeLatte.setName("Latte");
		recipeLatte.setPrice(50);
		recipeLatte.setAmtCoffee(5);
		recipeLatte.setAmtMilk(2);
		recipeLatte.setAmtSugar(1);
		recipeLatte.setAmtChocolate(0);

		recipeMocha = new Recipe();
		recipeMocha.setName("Mocha");
		recipeMocha.setPrice(50);
		recipeMocha.setAmtCoffee(6);
		recipeMocha.setAmtMilk(1);
		recipeMocha.setAmtSugar(1);
		recipeMocha.setAmtChocolate(0);
		
		recipeCappuccino = new Recipe();
		recipeCappuccino.setName("Cappuccino");
		recipeCappuccino.setPrice(50);
		recipeCappuccino.setAmtCoffee(6);
		recipeCappuccino.setAmtMilk(1);
		recipeCappuccino.setAmtSugar(1);
		recipeCappuccino.setAmtChocolate(0);
		

		recipeFrappuccino = new Recipe();
		recipeFrappuccino.setName("Frappuccino");
		recipeFrappuccino.setPrice(50);
		recipeFrappuccino.setAmtCoffee(6);
		recipeFrappuccino.setAmtMilk(1);
		recipeFrappuccino.setAmtSugar(1);
		recipeFrappuccino.setAmtChocolate(0);
		
	}
	
	
	/**
	 * Tear down.
	 *
	 * @throws Exception the exception
	 */
	@After
	public void tearDown() throws Exception {
		
	}

	
	

	/**
	 *Test the AddRecipe method of CoffeeMaker
	 *PostCondition: Test Run will be true if added recipe matches with the recipe for that name.
	 *
	 */	
	@Test public void testAddRecipe_Good() {
		myCoffeeMaker.addRecipe(recipeCoffee);
		assertEquals(recipeCoffee, myCoffeeMaker.getRecipeForName("Coffee"));		
	}

	/**
	 *Test the AddRecipe method of CoffeeMaker for Duplicate recipe
	 *PostCondition: Test Run will be false if trying to add the recipe if it is already present.
	 *
	 */	
	@Test 
	public void testAddRecipe_DuplicateRecipe() {
		myCoffeeMaker.addRecipe(recipeCoffee);
		myCoffeeMaker.addRecipe(recipeFrappuccino);
		myCoffeeMaker.addRecipe(recipeMocha);
		myCoffeeMaker.addRecipe(recipeLatte);
		assertFalse(myCoffeeMaker.addRecipe(recipeLatte));		
	}
	

	/**
	 *Test the AddRecipe method of CoffeeMaker for the number of recipes that can be added.
	 *PostCondition: Test Run will be false if trying to add more than 4 recipes.
	 *
	 */	
	@Test 
	public void testAddRecipe_RecipeFull() {
		myCoffeeMaker.addRecipe(recipeCoffee);
		myCoffeeMaker.addRecipe(recipeFrappuccino);
		myCoffeeMaker.addRecipe(recipeMocha);
		myCoffeeMaker.addRecipe(recipeLatte);
		assertFalse(myCoffeeMaker.addRecipe(recipeCappuccino));		
	}
	
	/**
	 *Test the DeleteRecipe method of CoffeeMaker for a recipe to be deleted.
	 *PostCondition: Test Run will be true if trying to delete a recipe that is present in the machine.
	 *
	 */	
	@Test	
	public void testDeleteRecipe1() {
		myCoffeeMaker.addRecipe(recipeCappuccino);
		assertTrue(myCoffeeMaker.deleteRecipe(recipeCappuccino));
	}

	/**
	 *Test the DeleteRecipe method of CoffeeMaker for a null recipe.
	 *PostCondition: Test Run will be false if trying to delete a recipe that is null.
	 *
	 */	
	@Test	
	public void testDeleteRecipe3() {
		//myCoffeeMaker.addRecipe(recipeCappuccino);
		Recipe newRecipe = null;
		assertFalse(myCoffeeMaker.deleteRecipe(newRecipe));
	}

	/**
	 *Test the DeleteRecipe method of CoffeeMaker for a recipe to be deleted that is not present in the machine.
	 *PostCondition: Test Run will be false if trying to delete a recipe that is not present in the machine.
	 *
	 */	
	@Test	
	public void testDeleteRecipe2() {
		//myCoffeeMaker.addRecipe(recipeCappuccino);
		assertFalse(myCoffeeMaker.deleteRecipe(recipeCappuccino));
	}

	
	/**
	 *Test the EditRecipe method of CoffeeMaker for a recipe to be edited.
	 *PostCondition: Test Run will be true if trying to edit a correct recipe that is present in the machine.
	 *
	 */	
	@Test	
	public void testEditRecipe1() {
		myCoffeeMaker.addRecipe(recipeCoffee);
		Recipe newRecipe = new Recipe();
		newRecipe = recipeCoffee;
		newRecipe.setAmtSugar(5);
		assertTrue(myCoffeeMaker.editRecipe(recipeCoffee, newRecipe));
	}
	
	/**
	 *Test the EditRecipe method of CoffeeMaker for a recipe to be edited.
	 *PostCondition: Test Run will be false if trying to edit a recipe that is not present in the machine.
	 *
	 */	
	@Test	
	public void testEditRecipe2() {
		//Recipe newRecipe = new Recipe();
		//newRecipe = recipeCoffee;
		//newRecipe.setAmtSugar(5);
		assertFalse(myCoffeeMaker.editRecipe(recipeCoffee, recipeFrappuccino));
	}
	
	
	/**
	 *Test the addInventory method of CoffeeMaker for a recipe to be edited.
	 *PostCondition: Test Run will be true if trying to add positive amounts of Coffee,Milk,Sugar,Chocolate in the machine.
	 *
	 */	
	@Test	
	public void testaddInventory() {
		assertTrue(myCoffeeMaker.addInventory(1, 3, 2, 1));
	}
	

	/**
	 *Test the addInventory method of CoffeeMaker for a recipe to be edited.
	 *PostCondition: Test Run will be false if trying to add negative amounts of Coffee,Milk,Sugar,Chocolate in the machine.
	 *
	 */	
	@Test	
	public void testaddInventory_negative_values() {
		assertFalse(myCoffeeMaker.addInventory(-1, -13, -12, -11));
	}


	/**
	 *Test the addInventory method of CoffeeMaker for a recipe to be edited.
	 *PostCondition: Test Run will be false if trying to add negative amounts of Coffee,Milk,Sugar,Chocolate in the machine.
	 *
	 */	
	@Test	
	public void testaddInventory_negative_values2() {
		assertFalse(myCoffeeMaker.addInventory(-1, -13, 12, 11));
	}

	/**
	 *Test the addInventory method of CoffeeMaker for a recipe to be edited.
	 *PostCondition: Test Run will be false if trying to add negative amounts of Coffee,Milk,Sugar,Chocolate in the machine.
	 *
	 */	
	@Test	
	public void testaddInventory_negative_values3() {
		assertFalse(myCoffeeMaker.addInventory(-1, -13, -12, 11));
	}

	/**
	 *Test the addInventory method of CoffeeMaker for a recipe to be edited.
	 *PostCondition: Test Run will be false if trying to add negative amounts of Coffee,Milk,Sugar,Chocolate in the machine.
	 *
	 */	
	@Test	
	public void testaddInventory_negative_values4() {
		assertFalse(myCoffeeMaker.addInventory(-1, 13, 12, 11));
	}

	
	/**
	 *Test the addInventory method of CoffeeMaker for a recipe to be edited.
	 *PostCondition: Test Run will be false if trying to add negative amounts of Coffee,Milk,Sugar,Chocolate in the machine.
	 *
	 */	
	@Test	
	public void testaddInventory_3() {
	    inventory.setChocolate(5);
	    inventory.setCoffee(5);
	    inventory.setMilk(5);
	    inventory.setSugar(5);
	    myCoffeeMaker.addInventory(40, 42, 43, 40);
	    
	    Inventory inv = myCoffeeMaker.checkInventory();
	    
	    assertEquals(45, inv.getCoffee());
	    assertEquals(47, inv.getMilk());
	    assertEquals(48, inv.getSugar());
	    assertEquals(45, inv.getChocolate());
	}

	
	

	/**
	 *Test the checkInventory method of CoffeeMaker for a recipe to be edited.
	 *PostCondition: Test Run will be false if trying to add negative amounts of Coffee,Milk,Sugar,Chocolate in the machine.
	 *
	 */	
	@Test	
	public void testcheckInventory() {
		myCoffeeMaker.addInventory(2, 2, 3, 3);
		assertEquals(inventory.getSugar(), myCoffeeMaker.checkInventory().getSugar());
		assertEquals(inventory.getCoffee(), myCoffeeMaker.checkInventory().getCoffee());
		assertEquals(inventory.getMilk(), myCoffeeMaker.checkInventory().getMilk());
		assertEquals(inventory.getChocolate(), myCoffeeMaker.checkInventory().getChocolate());
	}

	/**
	 *Test the makeCoffee method.
	 *PostCondition: Test Run will be true if trying to make coffee with enough price amount.
	 *
	 */	
	@Test	
	public void testmakeCoffee() {
		assertEquals(10, myCoffeeMaker.makeCoffee(recipeCappuccino, 60));
	}
	
	/**
	 *Test the makeCoffee method.
	 *PostCondition: Test Run to test the returned money and inserted money are the same, if trying to make coffee without enough price amount.
	 *
	 */	
	@Test	
	public void testmakeCoffee2() {
		assertEquals(40, myCoffeeMaker.makeCoffee(recipeCappuccino, 40));
	}
	
	
	/**
	 *Test the makeCoffee method.
	 *PostCondition: Test Run to test the returned money and inserted money are the same, if trying to make coffee without enough price amount.
	 *
	 */	
	@Test	
	public void testmakeCoffee3() {
	    inventory.setChocolate(0);
	    inventory.setCoffee(0);
	    inventory.setMilk(0);
	    inventory.setSugar(0);
	    
	    assertEquals(40, myCoffeeMaker.makeCoffee(recipeCappuccino, 40));
	}
	
	/**
	 *Test the makeCoffee method.
	 *PostCondition: Test Run to test the returned money and inserted money are the same, if trying to make coffee without enough price amount.
	 *
	 */	
	@Test	
	public void testmakeCoffee4() {
	    inventory.setChocolate(10);
	    inventory.setCoffee(10);
	    inventory.setMilk(10);
	    inventory.setSugar(10);
	    
	    assertEquals(50, myCoffeeMaker.makeCoffee(recipeCappuccino, 100));
	}
	
	/**
	 *Test the makeCoffee method.
	 *PostCondition: Test Run to test the returned money and inserted money are the same, if trying to make coffee without enough price amount.
	 *
	 */	
	@Test	
	public void testmakeCoffee5() {
	    inventory.setChocolate(10);
	    inventory.setCoffee(10);
	    inventory.setMilk(10);
	    inventory.setSugar(10);
	    
	    assertEquals(50, myCoffeeMaker.makeCoffee(recipeCappuccino, 100));
	}
	
	
}